package org.marsson.bNav;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * Demo.java:   Allows player to pick locations and select targets
 * @author      William Dubel
 * @version     1.0    June 29, 2001
 */

class ServerGame extends Game implements Runnable
{
	static final String LOG_PROPERTIES_FILE = "src/main/resources/log4j.properties";

	Logger logger =Logger.getLogger(this.getClass());
	protected PlayingField mainHandle;
	BattleShip battleship;
	ServerGame(BattleShip battleship)
	{
		super("Batalha Naval",battleship);
		new Thread(this, "Game Server").start();
		this.battleship=battleship;
		initializeLogger(); 
		 
		
	}

	public void run()
	{
		if (BattleShip.soundOn()) Sound.start.play();
		
		
		
		
		
		myField.placeShips();
		battleship.serialComm.execute();
		battleship.serialComm.initwritetoport();
		
					
		while (demoRunning)
		{
			
			atira();
			//Pega a resposta do oponente...
			logger.info("Esperando tiro adversario");
			esperaTiro();
			logger.info("Tiro recebido");
		}
	}

	private void initializeLogger()
	  {
	    Properties logProperties = new Properties();

	    try
	    {
	      // load our log4j properties / configuration file
	      logProperties.load(new FileInputStream(LOG_PROPERTIES_FILE));
	      PropertyConfigurator.configure(logProperties);
	      logger.info("Logging initialized.");
	    }
	    catch(IOException e)
	    {
	      throw new RuntimeException("Unable to load logging property " + LOG_PROPERTIES_FILE);
	    }
	  }


}
